package com.bear.newsset.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.NonNull;

public class SQLAction {
    private static final String DB_NAME = "db_newsset.db";
    private DaoSession session;
    private SQLAction() {}

    public static SQLAction getInstance() {
        return HANDLER.INSTANCE;
    }

    private static final class HANDLER {
        private static final SQLAction INSTANCE = new SQLAction();
    }

    public void init(Context mContext) {
//        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(mContext, DB_NAME);
        SQLOpenHelper helper = new SQLOpenHelper(mContext, DB_NAME, null);
        SQLiteDatabase db = helper.getWritableDatabase();
        DaoMaster master = new DaoMaster( db );
        session = master.newSession();
    }

    @NonNull
    public DaoSession getDaoSession() {
        if( session != null ) return session;
        throw new NullPointerException("Need to be init, You can call the init(Context).");
    }

    @NonNull
    public NewsDataSqlEntityDao getNewsDataSqlEntityDao() {
        return getDaoSession().getNewsDataSqlEntityDao();
    }

    @NonNull
    public QueryNewsDataEntityDao getQueryNewsDataEntityDao() {
        return getDaoSession().getQueryNewsDataEntityDao();
    }

    @NonNull
    public ImageSqlEntityDao getImageSqlEntityDao() {
        return getDaoSession().getImageSqlEntityDao();
    }

    @NonNull
    public StringMapSqlEntityDao getStringMapSqlEntityDao() {
        return getDaoSession().getStringMapSqlEntityDao();
    }

    @NonNull
    public NewsStatusSqlEntityDao getNewsStatusSqlEntityDao() {
        return getDaoSession().getNewsStatusSqlEntityDao();
    }

    @NonNull
    public NewsLikeSqlEntityDao getNewsLikeSqlEntityDao() {
        return getDaoSession().getNewsLikeSqlEntityDao();
    }

    @NonNull
    public AccountEntityDao getAccountEntityDao() {
        return getDaoSession().getAccountEntityDao();
    }
}
